package cn.dujc.superkid.adapter.cup;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.dujc.core.adapter.BaseQuickAdapter;
import cn.dujc.core.adapter.BaseViewHolder;
import cn.dujc.superkid.R;
import cn.dujc.superkid.adapter.MessageEntityAdapter;
import cn.dujc.superkid.bean.CupListResult;
import cn.dujc.superkid.bean.MessageEntity;
import cn.dujc.superkid.utils.DateUtil;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2018/10/17 0017.
 */

public class CupMessageEntityAdapter extends BaseQuickAdapter<CupListResult.VideoMessageBean,CupMessageEntityAdapter.ViewHolder> {
    public void setDatas(List<CupListResult.VideoMessageBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    private List<CupListResult.VideoMessageBean>datas;
    public CupMessageEntityAdapter(int layoutResId, @Nullable List<CupListResult.VideoMessageBean> data) {
        super(R.layout.item_message_entity, data);
    }
    public void setContext(Context context){
        this.context=context;
    }
    @Override
    public CupMessageEntityAdapter.ViewHolder createBaseViewHolder(View view) {
        return new CupMessageEntityAdapter.ViewHolder(view);
    }
    @Override
    protected void convert(ViewHolder holder, CupListResult.VideoMessageBean item) {
        holder.userName.setText(item.getUsername());
        holder.userTime.setText(DateUtil.formatData("yyyy-MM-dd HH:mm:ss", item.getPosttime()));
        holder.userMessage.setText(item.getContent());
        Glide.with(context).load(item.getAvatar()).into(holder.userAvatar);
        Log.e("avatar",item.getAvatar());
        if (item.getStatus() == 1) {
            holder.teacherGroup.setVisibility(View.GONE);
            holder.waitGroup.setVisibility(View.VISIBLE);
        } else {
            holder.teacherGroup.setVisibility(View.VISIBLE);
            holder.waitGroup.setVisibility(View.GONE);
            holder.teacherName.setText(item.getAnswer_teacher_nicename());
            Glide.with(context).load(item.getAnswer_teacher_avatar()).into(holder.teacherAvatar);
            Glide.with(context).load(item.getAvatar()).into(holder.userAvatar);
            holder.teacherMessage.setText(item.getAnswer_content());
            holder.teacherTime.setText(DateUtil.formatData("yyyy-MM-dd HH:mm:ss",item.getAnswer_posttime()));
        }
    }
    private Context context;

    static class ViewHolder extends BaseViewHolder {
        CircleImageView userAvatar, teacherAvatar;
        TextView userName, userTime, userMessage;
        TextView teacherName, teacherTime, teacherMessage;
        View teacherGroup, waitGroup;

        public ViewHolder(View itemView) {
            super(itemView);
            userAvatar = itemView.findViewById(R.id.item_message_avatar);
            teacherAvatar = itemView.findViewById(R.id.item_message_teacher_avatar);
            userName = itemView.findViewById(R.id.item_message_username);
            userTime = itemView.findViewById(R.id.item_message_user_time);
            userMessage = itemView.findViewById(R.id.item_message_user_message);
            teacherName = itemView.findViewById(R.id.item_message_teacher_name);
            teacherTime = itemView.findViewById(R.id.item_message_teacher_time);
            teacherMessage = itemView.findViewById(R.id.item_message_teacher_message);
            teacherGroup = itemView.findViewById(R.id.item_message_teacher_group);
            waitGroup = itemView.findViewById(R.id.item_message_is_wait);

        }
    }
}

